/*     */ package com.zimbra.cs.redolog.op;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.cs.mailbox.MailItem.TargetConstraint;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.MailboxOperation;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailbox.util.TagUtil;
/*     */ import com.zimbra.cs.redolog.RedoLogInput;
/*     */ import com.zimbra.cs.redolog.RedoLogOutput;
/*     */ import com.zimbra.cs.redolog.Version;
/*     */ import java.io.IOException;
/*     */ import java.util.Arrays;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AlterItemTag
/*     */   extends RedoableOp
/*     */ {
/*     */   private int[] mIds;
/*     */   private MailItem.Type type;
/*     */   private String mTagName;
/*     */   private int mTagId;
/*     */   private boolean mTagged;
/*     */   private String mConstraint;
/*     */   
/*     */   public AlterItemTag()
/*     */   {
/*  46 */     super(MailboxOperation.AlterItemTag);
/*  47 */     this.type = MailItem.Type.UNKNOWN;
/*  48 */     this.mTagId = 0;
/*  49 */     this.mTagged = false;
/*  50 */     this.mConstraint = null;
/*     */   }
/*     */   
/*     */   public AlterItemTag(int mailboxId, int[] ids, MailItem.Type type, String tag, boolean tagged, MailItem.TargetConstraint tcon) {
/*  54 */     this();
/*  55 */     setMailboxId(mailboxId);
/*  56 */     this.mIds = ids;
/*  57 */     this.type = type;
/*  58 */     this.mTagName = tag;
/*  59 */     this.mTagged = tagged;
/*  60 */     this.mConstraint = (tcon == null ? null : tcon.toString());
/*     */   }
/*     */   
/*     */   protected String getPrintableData()
/*     */   {
/*  65 */     StringBuffer sb = new StringBuffer("ids=");
/*  66 */     sb.append(Arrays.toString(this.mIds)).append(", type=").append(this.type);
/*  67 */     sb.append(", tag=").append(this.mTagName == null ? "" + this.mTagId : this.mTagName).append(", tagged=").append(this.mTagged);
/*  68 */     if (this.mConstraint != null) {
/*  69 */       sb.append(", constraint=").append(this.mConstraint);
/*     */     }
/*  71 */     return sb.toString();
/*     */   }
/*     */   
/*     */   protected void serializeData(RedoLogOutput out) throws IOException
/*     */   {
/*  76 */     boolean hasConstraint = this.mConstraint != null;
/*  77 */     out.writeInt(-1);
/*  78 */     out.writeByte(this.type.toByte());
/*  79 */     if (getVersion().atLeast(1, 33)) {
/*  80 */       out.writeUTF(this.mTagName);
/*     */     } else {
/*  82 */       out.writeInt(this.mTagId);
/*     */     }
/*  84 */     out.writeBoolean(this.mTagged);
/*  85 */     out.writeBoolean(hasConstraint);
/*  86 */     if (hasConstraint) {
/*  87 */       out.writeUTF(this.mConstraint);
/*     */     }
/*  89 */     out.writeInt(this.mIds == null ? 0 : this.mIds.length);
/*  90 */     if (this.mIds != null) {
/*  91 */       for (int i = 0; i < this.mIds.length; i++) {
/*  92 */         out.writeInt(this.mIds[i]);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   protected void deserializeData(RedoLogInput in) throws IOException
/*     */   {
/*  99 */     int id = in.readInt();
/* 100 */     if (id > 0) {
/* 101 */       this.mIds = new int[] { id };
/*     */     }
/* 103 */     this.type = MailItem.Type.of(in.readByte());
/* 104 */     if (getVersion().atLeast(1, 33)) {
/* 105 */       this.mTagName = in.readUTF();
/*     */     } else {
/* 107 */       this.mTagId = in.readInt();
/*     */     }
/* 109 */     this.mTagged = in.readBoolean();
/* 110 */     if (in.readBoolean()) {
/* 111 */       this.mConstraint = in.readUTF();
/*     */     }
/* 113 */     if (id <= 0) {
/* 114 */       this.mIds = new int[in.readInt()];
/* 115 */       for (int i = 0; i < this.mIds.length; i++) {
/* 116 */         this.mIds[i] = in.readInt();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void redo() throws Exception
/*     */   {
/* 123 */     Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
/*     */     
/* 125 */     OperationContext octxt = getOperationContext();
/*     */     
/* 127 */     MailItem.TargetConstraint tcon = null;
/* 128 */     if (this.mConstraint != null) {
/*     */       try {
/* 130 */         tcon = MailItem.TargetConstraint.parseConstraint(mbox, this.mConstraint);
/*     */       } catch (ServiceException e) {
/* 132 */         mLog.warn(e);
/*     */       }
/*     */     }
/*     */     
/* 136 */     if ((this.mTagName == null) && (this.mTagId != 0)) {
/* 137 */       this.mTagName = TagUtil.tagIdToName(mbox, octxt, this.mTagId);
/*     */     }
/*     */     
/* 140 */     mbox.alterTag(octxt, this.mIds, this.type, this.mTagName, this.mTagged, tcon);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/redolog/op/AlterItemTag.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */